﻿
Imports osi.root.connector
Imports osi.root.procedure
Imports osi.root.formation
Imports osi.root.utils

Public Class one_off_device_pool(Of T)
    Inherits device_pool(Of T)
    Implements iasync_device_pool(Of T)

    Public Sub New(ByVal max_count As UInt32,
                   ByVal identity As String,
                   Optional ByVal ctor As Func(Of pointer(Of T), event_comb) = Nothing,
                   Optional ByVal validator As Func(Of T, Boolean) = Nothing,
                   Optional ByVal closer As Action(Of T) = Nothing,
                   Optional ByVal device_id As Func(Of T, String) = Nothing)
        MyBase.New(max_count, identity, ctor, validator, closer, device_id)
    End Sub

    Public Sub New(ByVal max_count As UInt32,
                   Optional ByVal ctor As Func(Of pointer(Of T), event_comb) = Nothing,
                   Optional ByVal validator As Func(Of T, Boolean) = Nothing,
                   Optional ByVal closer As Action(Of T) = Nothing,
                   Optional ByVal device_id As Func(Of T, String) = Nothing)
        MyBase.New(max_count, ctor, validator, closer, device_id)
    End Sub

    Public Sub New(ByVal identity As String,
                   Optional ByVal ctor As Func(Of pointer(Of T), event_comb) = Nothing,
                   Optional ByVal validator As Func(Of T, Boolean) = Nothing,
                   Optional ByVal closer As Action(Of T) = Nothing,
                   Optional ByVal device_id As Func(Of T, String) = Nothing)
        MyBase.New(identity, ctor, validator, closer, device_id)
    End Sub

    Public Sub New(Optional ByVal ctor As Func(Of pointer(Of T), event_comb) = Nothing,
                   Optional ByVal validator As Func(Of T, Boolean) = Nothing,
                   Optional ByVal closer As Action(Of T) = Nothing,
                   Optional ByVal device_id As Func(Of T, String) = Nothing)
        MyBase.New(ctor, validator, closer, device_id)
    End Sub

    Protected NotOverridable Overrides Function get_free_count() As UInt32
        Return MyBase.get_free_count()
    End Function

    Protected NotOverridable Overrides Function sync_get_device(ByRef r As T) As Boolean
        assert(False)
        Return False
    End Function

    Protected NotOverridable Overrides Sub close_devices()
        MyBase.close_devices()
    End Sub

    Protected NotOverridable Overrides Function get_device(ByVal r As pointer(Of T)) As event_comb
        Return create_new_device(r)
    End Function

    Protected NotOverridable Overrides Function release_device(ByVal c As T) As Boolean
        close_existing_device(c)
        Return True
    End Function

    Public Shadows Function [get](ByVal o As pointer(Of T)) As event_comb Implements iasync_device_pool(Of T).get
        Return MyBase.[get](o)
    End Function

    Public Shadows Function release(ByVal c As T) As Boolean Implements idevice_pool(Of T).release
        Return MyBase.release(c)
    End Function
End Class
